package com.zyy.datasourcemanagement.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Map;

@Aspect
@Component
public class DataSourceAspect {

    @Pointcut("@annotation(com.zyy.datasourcemanagement.aspect.annotation.MyDataSource)")
    public void dataSource(){}
    @Before("dataSource()")
    public void before(JoinPoint joinPoint){
        System.out.println("前置通知");
        Object[] args= joinPoint.getArgs();
        for (Object o: args){
            System.out.println(o);
        }
    }

    @After("dataSource()")
    public void after(){
        System.out.println("后置通知");
    }

    @Around("dataSource()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object[] args= pjp.getArgs();
        System.out.println("执行方法前");
        // 执行方法
        Object res = pjp.proceed(args);
        System.out.println("执行方法后");
        return res;
    }

    @AfterReturning("dataSource()")
    public void afterReturning(){
        System.out.println("结果通知");
    }

    @AfterThrowing("dataSource()")
    public void afterThrowing(){
        System.out.println("异常通知");
    }


}
